/*
 * @Author: Starfish_DL
 * @Date: 2020-11-15 00:29:56
 * @LastEditors: Starfish_DL
 * @LastEditTime: 2020-11-15 00:43:07
 * @CurrentVersion: 1.0
 * @Description: 
 */

class CountTarget implements Runnable {

    static volatile int count = 1;

    @Override
    public void run() {
        while (true) {
            synchronized (this) {
                notifyAll();
                if (count > 100) {
                    break;
                }
                System.out.println(Thread.currentThread().getName() + ":" + count);
                count++;
                try {
                    wait();
                } catch (InterruptedException e) {
                    System.out.println(e.getStackTrace());
                }
            }
        }
    }
}

public class Test003 {
    public static void main(String[] args) {
        CountTarget tar = new CountTarget();
        Thread th1 = new Thread(tar, "thread1");
        Thread th2 = new Thread(tar, "thread2");
        th1.start();
        th2.start();
    }
}
